###############################################################################
##
##  Copyright (C) 2014 Tavendo GmbH
##
##  Licensed under the Apache License, Version 2.0 (the "License");
##  you may not use this file except in compliance with the License.
##  You may obtain a copy of the License at
##
##      http://www.apache.org/licenses/LICENSE-2.0
##
##  Unless required by applicable law or agreed to in writing, software
##  distributed under the License is distributed on an "AS IS" BASIS,
##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
##  See the License for the specific language governing permissions and
##  limitations under the License.
##
###############################################################################

## Image file names to process
SVG_FILES = [
]

## Directory with image files to process
IMG_SOURCE_DIR = "design"

## Processed image files are placed here
IMG_GEN_DIR    = "_static/img/gen"

## Directory to upload
DOCSDIR = '_build'

## Contains fingerprints of uploaded files
UPLOADED = '_build_uploaded'

## The Tavendo S3 Bucket to upload to
BUCKET = 'autobahn.ws'

## The Bucket Prefix to upload files to
BUCKET_PREFIX = 'android'

## Tavendo shared static assets
CSTATIC = "//tavendo-common-static.s3-eu-west-1.amazonaws.com"
CSTATIC_LOCAL = "http://127.0.0.1:8888"


### END OF CONFIG #############################################################


import os
import json
import pkg_resources

os.environ['PYTHONPATH'] = '../autobahn'

taschenmesser = pkg_resources.resource_filename('taschenmesser', '..')
#taschenmesser = "../../../infrequent/taschenmesser"

AddOption('--no_network', dest = 'no_network', action = 'store_true', default = False,
   help = "Run locally and disable anything doing network access")

env = Environment(tools = ['default', 'taschenmesser'],
                  toolpath = [taschenmesser],
                  ENV = os.environ)

## Process SVGs
##
imgs = env.process_svg(SVG_FILES, IMG_SOURCE_DIR, IMG_GEN_DIR)

Alias("img", imgs)


## Sphinx Build
##
if GetOption('no_network'):
   print("Building for no network")
   docs = env.Command(DOCSDIR, [], 'sphinx-build -A no_network=1 -D no_network=1 -A cstatic="{}" -b html . $TARGET'.format(CSTATIC_LOCAL))
else:
   docs = env.Command(DOCSDIR, [], 'sphinx-build -A cstatic="{}" -b html . $TARGET'.format(CSTATIC))


# sphinx-build -b spelling . _spelling

env.AlwaysBuild(docs)
Clean(docs, DOCSDIR)
Alias("doc", docs)

Default([imgs, docs])



## Upload to Amazon S3
##
uploaded = env.s3_dir_uploader(UPLOADED, DOCSDIR, BUCKET, BUCKET_PREFIX)

Depends(uploaded, docs)
Depends(uploaded, imgs)

Clean(uploaded, UPLOADED)

Alias("publish", uploaded)
